using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace SurveyHost.Core.DAL
{
	/// <summary>
	/// Strongly-typed collection for the Content class.
	/// </summary>
	[Serializable]
	public partial class ContentCollection : ActiveList<Content, ContentCollection> 
	{	   
		public ContentCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Content table.
	/// </summary>
	[Serializable]
	public partial class Content : ActiveRecord<Content>
	{
		#region .ctors and Default Settings
		
		public Content()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Content(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Content(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Content(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Content", TableType.Table, DataService.GetInstance("SurveyHost"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarContentId = new TableSchema.TableColumn(schema);
				colvarContentId.ColumnName = "ContentId";
				colvarContentId.DataType = DbType.Int32;
				colvarContentId.MaxLength = 0;
				colvarContentId.AutoIncrement = true;
				colvarContentId.IsNullable = false;
				colvarContentId.IsPrimaryKey = true;
				colvarContentId.IsForeignKey = false;
				colvarContentId.IsReadOnly = false;
				colvarContentId.DefaultSetting = @"";
				colvarContentId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContentId);
				
				TableSchema.TableColumn colvarContentGUID = new TableSchema.TableColumn(schema);
				colvarContentGUID.ColumnName = "ContentGUID";
				colvarContentGUID.DataType = DbType.Guid;
				colvarContentGUID.MaxLength = 0;
				colvarContentGUID.AutoIncrement = false;
				colvarContentGUID.IsNullable = false;
				colvarContentGUID.IsPrimaryKey = false;
				colvarContentGUID.IsForeignKey = false;
				colvarContentGUID.IsReadOnly = false;
				
						colvarContentGUID.DefaultSetting = @"(newid())";
				colvarContentGUID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContentGUID);
				
				TableSchema.TableColumn colvarTitle = new TableSchema.TableColumn(schema);
				colvarTitle.ColumnName = "Title";
				colvarTitle.DataType = DbType.String;
				colvarTitle.MaxLength = 500;
				colvarTitle.AutoIncrement = false;
				colvarTitle.IsNullable = true;
				colvarTitle.IsPrimaryKey = false;
				colvarTitle.IsForeignKey = false;
				colvarTitle.IsReadOnly = false;
				colvarTitle.DefaultSetting = @"";
				colvarTitle.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTitle);
				
				TableSchema.TableColumn colvarContentName = new TableSchema.TableColumn(schema);
				colvarContentName.ColumnName = "ContentName";
				colvarContentName.DataType = DbType.String;
				colvarContentName.MaxLength = 50;
				colvarContentName.AutoIncrement = false;
				colvarContentName.IsNullable = false;
				colvarContentName.IsPrimaryKey = false;
				colvarContentName.IsForeignKey = false;
				colvarContentName.IsReadOnly = false;
				colvarContentName.DefaultSetting = @"";
				colvarContentName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarContentName);
				
				TableSchema.TableColumn colvarBody = new TableSchema.TableColumn(schema);
				colvarBody.ColumnName = "Body";
				colvarBody.DataType = DbType.String;
				colvarBody.MaxLength = -1;
				colvarBody.AutoIncrement = false;
				colvarBody.IsNullable = true;
				colvarBody.IsPrimaryKey = false;
				colvarBody.IsForeignKey = false;
				colvarBody.IsReadOnly = false;
				colvarBody.DefaultSetting = @"";
				colvarBody.ForeignKeyTableName = "";
				schema.Columns.Add(colvarBody);
				
				TableSchema.TableColumn colvarLocale = new TableSchema.TableColumn(schema);
				colvarLocale.ColumnName = "Locale";
				colvarLocale.DataType = DbType.String;
				colvarLocale.MaxLength = 7;
				colvarLocale.AutoIncrement = false;
				colvarLocale.IsNullable = false;
				colvarLocale.IsPrimaryKey = false;
				colvarLocale.IsForeignKey = false;
				colvarLocale.IsReadOnly = false;
				
						colvarLocale.DefaultSetting = @"(N'en-US')";
				colvarLocale.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLocale);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "CreatedOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "CreatedBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "ModifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "ModifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["SurveyHost"].AddSchema("Content",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("ContentId")]
		public int ContentId 
		{
			get { return GetColumnValue<int>("ContentId"); }

			set { SetColumnValue("ContentId", value); }

		}

		  
		[XmlAttribute("ContentGUID")]
		public Guid ContentGUID 
		{
			get { return GetColumnValue<Guid>("ContentGUID"); }

			set { SetColumnValue("ContentGUID", value); }

		}

		  
		[XmlAttribute("Title")]
		public string Title 
		{
			get { return GetColumnValue<string>("Title"); }

			set { SetColumnValue("Title", value); }

		}

		  
		[XmlAttribute("ContentName")]
		public string ContentName 
		{
			get { return GetColumnValue<string>("ContentName"); }

			set { SetColumnValue("ContentName", value); }

		}

		  
		[XmlAttribute("Body")]
		public string Body 
		{
			get { return GetColumnValue<string>("Body"); }

			set { SetColumnValue("Body", value); }

		}

		  
		[XmlAttribute("Locale")]
		public string Locale 
		{
			get { return GetColumnValue<string>("Locale"); }

			set { SetColumnValue("Locale", value); }

		}

		  
		[XmlAttribute("CreatedOn")]
		public DateTime? CreatedOn 
		{
			get { return GetColumnValue<DateTime?>("CreatedOn"); }

			set { SetColumnValue("CreatedOn", value); }

		}

		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>("CreatedBy"); }

			set { SetColumnValue("CreatedBy", value); }

		}

		  
		[XmlAttribute("ModifiedOn")]
		public DateTime? ModifiedOn 
		{
			get { return GetColumnValue<DateTime?>("ModifiedOn"); }

			set { SetColumnValue("ModifiedOn", value); }

		}

		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>("ModifiedBy"); }

			set { SetColumnValue("ModifiedBy", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(Guid varContentGUID,string varTitle,string varContentName,string varBody,string varLocale,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			Content item = new Content();
			
			item.ContentGUID = varContentGUID;
			
			item.Title = varTitle;
			
			item.ContentName = varContentName;
			
			item.Body = varBody;
			
			item.Locale = varLocale;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varContentId,Guid varContentGUID,string varTitle,string varContentName,string varBody,string varLocale,DateTime? varCreatedOn,string varCreatedBy,DateTime? varModifiedOn,string varModifiedBy)
		{
			Content item = new Content();
			
				item.ContentId = varContentId;
				
				item.ContentGUID = varContentGUID;
				
				item.Title = varTitle;
				
				item.ContentName = varContentName;
				
				item.Body = varBody;
				
				item.Locale = varLocale;
				
				item.CreatedOn = varCreatedOn;
				
				item.CreatedBy = varCreatedBy;
				
				item.ModifiedOn = varModifiedOn;
				
				item.ModifiedBy = varModifiedBy;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string ContentId = @"ContentId";
			 public static string ContentGUID = @"ContentGUID";
			 public static string Title = @"Title";
			 public static string ContentName = @"ContentName";
			 public static string Body = @"Body";
			 public static string Locale = @"Locale";
			 public static string CreatedOn = @"CreatedOn";
			 public static string CreatedBy = @"CreatedBy";
			 public static string ModifiedOn = @"ModifiedOn";
			 public static string ModifiedBy = @"ModifiedBy";
						
		}

		#endregion
	}

}

